//
//  MXMessageCenterController.m
//  HNBaseProject
//
//  Created by xujie on 2024/6/4.
//

#import "MXMessageCenterController.h"
#import "MxPublicNav.h"
#import "MXEquipmentNoticeController.h"
#import "MXSystemNoticeController.h"

@interface MXMessageCenterController () <MxNavigationViewDelegate,JXPagerViewDelegate, JXCategoryViewDelegate>
@property (nonatomic, strong) MxPublicNav *nav;
@property (nonatomic, strong) JXPagerView          *pagingView;
@property (nonatomic, strong) JXCategoryTitleView  *categoryView;
@property (nonatomic, assign)  CGFloat             JXTableHeaderViewHeight;//头部高度
@property (nonatomic, assign)  CGFloat             JXheightForHeaderInSection;//item高度
@property (nonatomic, strong) MXEquipmentNoticeController *equiVc;
@property (nonatomic, strong) MXSystemNoticeController    *noticeVc;


@end

@implementation MXMessageCenterController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self createUI];
}

- (void)createUI {
    self.nav = [[MxPublicNav alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kNavBarHeight)];
    self.nav.titleLab.text = @"消息中心";
    self.nav.delegate = self;
    [self.view addSubview:self.nav];
    
    self.JXTableHeaderViewHeight = 0;
    self.JXheightForHeaderInSection = 44;
    [self.view addSubview:self.categoryView];
    
    self.pagingView = [[JXPagerView alloc] initWithDelegate:self];
    self.pagingView.automaticallyDisplayListVerticalScrollIndicator=NO;
    self.pagingView.mainTableView.bounces = NO;
    self.pagingView.pinSectionHeaderVerticalOffset = self.JXTableHeaderViewHeight;
    [self.view addSubview:self.pagingView];
    self.categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagingView.listContainerView;
}

- (void)viewDidLayoutSubviews {
    
    [super viewDidLayoutSubviews];
    self.pagingView.frame = CGRectMake(0, kNavBarHeight+10 , kScreenW, kScreenH - kNavBarHeight - 10);

}

-(void)leftTap {
    [self.navigationController popViewControllerAnimated:YES];
}

- (JXCategoryTitleView *)categoryView {
    if (!_categoryView) {
        _categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, kNavBarHeight+10, kScreenW, 44)];
        _categoryView.backgroundColor =  UIColor.whiteColor;
        _categoryView.titles =  @[@"设备通知",@"系统通知"];
        _categoryView.delegate = self;
        _categoryView.titleColor = [UIColor colorWithHexString:@"#999999"];
        _categoryView.titleSelectedColor = [UIColor colorWithHexString:@"#333333"];
        _categoryView.titleFont = PFRFont(15);
        _categoryView.titleSelectedFont = PFRFontSemibold(18);
        _categoryView.cellBackgroundUnselectedColor = [UIColor clearColor];
        _categoryView.cellBackgroundSelectedColor = [UIColor clearColor];
        _categoryView.cellBackgroundColorGradientEnabled = YES;
        _categoryView.averageCellSpacingEnabled = NO;
        _categoryView.cellSpacing = 60;
        JXCategoryIndicatorLineView *line = [[JXCategoryIndicatorLineView alloc] init];
        line.indicatorWidth = 25;
        line.indicatorHeight = 3;
        line.indicatorColor = [UIColor colorWithHexString:@"#000000"];
        line.verticalMargin = 4;
        line.layer.cornerRadius = 1.5;
        _categoryView.indicators = @[line];
        
    }
    return _categoryView;
}
#pragma mark - JXPagingViewDelegate

- (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {

    return [[UIView alloc] init];
}

- (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
    
    return self.JXTableHeaderViewHeight;
}

- (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
    
    return self.JXheightForHeaderInSection;
}

- (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
    
    return self.categoryView;
}

- (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
    
    return 2;
}

- (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {

    if (index == 0) {
        
        return self.equiVc;
    }
    return self.noticeVc;

}

- (MXEquipmentNoticeController *)equiVc {
    if (!_equiVc) {
        _equiVc = [[MXEquipmentNoticeController alloc] init];
    }
    return _equiVc;
}

- (MXSystemNoticeController *)noticeVc {
    if (!_noticeVc) {
        _noticeVc = [[MXSystemNoticeController alloc] init];
    }
    return _noticeVc;
}


- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self dc_navBarHidden:YES];
}

@end
